import modeObject from './config';
import http from '@/lib/http';
import axios from 'axios'
import xxtea from 'xxtea'

export function get_example(uuid) {
  return http({
    url: `${modeObject.baseUrl}/api/user/article/click/${uuid}`,
    method: 'GET'
  })
}

export function post_example(data) {
  return http({
    url: `${modeObject.baseUrl}/api/user/article/page/list`,
    method: 'POST',
    data: data
  })
}

export async function decryptByXXtea(t) {
  const res = await axios({
    url: `${modeObject.imageUrl}${t}`,
    method: 'GET',
    responseType: 'arraybuffer'
  });

  const encryptData = new Int8Array(res.data);
  const decrypted = xxtea.decrypt(encryptData, modeObject.xxteaKey);
  const str = arrayBufferToBlob(decrypted); // 转换blob
  return str;
}

export function arrayBufferToBlob(buffer) {
  var bytes = new Uint8Array(buffer);
  const blob = new Blob([bytes]);
  var str = window.URL.createObjectURL(blob);

  return str;
}